<?php

class models_rule {

    private $_db;
    private $_cache;

    public function __construct($db, $cache) {
        $this->_db = $db;
        $this->_cache = $cache;
    }

    public function get_all() {

        if ($this->_cache->cache('all_rules') && global_vars::instance()->get('debug')) {
            return $this->_cache->cache('all_rules');
        } else {
            $gvars = global_vars::instance();
            $table_rule = $gvars->get('rule_test') == TRUE ? 'rule' : 'rule_compile';
            $rules = $this->_db->query("
                SELECT * 
                FROM `{$table_rule}`
                WHERE `enabled` = 1
                ORDER BY `order`
                ");
            $exce = $this->_db->getPDOException();
            if ($exce) {
                throw $exce;
            }
            $this->_cache->cache('all_rules', $rules);
            return $rules;
        }
    }
    
    
  
}

?>
